set more off
capture log close

//  program:    AnanatEtAl_test_score_unweighted
//  task:		Run Regressions for test score results using a specification unweighted by the sample size of the test takers in each state

//change working directory to point to the file with the data
cd *** Fill in path name here ***

//create log file
log using AnanatEtAl_test_score_unweighted, replace text

//load the merged bls naep data
use AnanatEtAl_test_score_data, clear

//set the panel variables
xtset stateno year

//run regressions without test-taker sample sizes as frequency weights

** All Students **
ivregress 2sls z_all yrd* stated* (seppctyrlag = ticpctyrlag), vce(cluster stateno) first
est store ALL
outreg2 [ALL] using test_score_unweighted, drop(yrd* stated*) excel replace dec(3)

** Black Students **
ivregress 2sls z_black yrd* stated* (seppctyrlag = ticpctyrlag), vce(cluster stateno) first
est store BLACK
outreg2 [BLACK] using test_score_unweighted, drop(yrd* stated*) excel dec(3) 

** White Students **
ivregress 2sls z_white yrd* stated* (seppctyrlag = ticpctyrlag), vce(cluster stateno) first
est store WHITE
outreg2 [WHITE] using test_score_unweighted, drop(yrd* stated*) excel dec(3)

** State-years with below median unemployment **
//generate the median unemployment cutoff
sort year
by year: egen cutoff = pctile(unemplag), p(50)
keep if unemplag<=cutoff
//run regression weighted by test-taker sample size
ivregress 2sls z_all yrd* stated* (seppctyrlag = ticpctyrlag), vce(cluster stateno) first
est store LOWUNEMP
outreg2 [LOWUNEMP] using test_score_unweighted, drop(yrd* stated*) excel dec(3)

clear all

** State-years with above median unemployment **
//load the data
use AnanatEtAl_test_score_data, clear
//set the panel variables
xtset stateno year
//generate the median unemployment cutoff value
sort year
by year: egen cutoff = pctile(unemplag), p(50)
keep if unemplag>cutoff
//run regression weighted by test-taker sample size
ivregress 2sls z_all yrd* stated* (seppctyrlag = ticpctyrlag), vce(cluster stateno) first
est store HIGHUNEMP
outreg2 [HIGHUNEMP] using test_score_unweighted, drop(yrd* stated*) excel dec(3)

clear all

log close
